define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_agentdemand_getlist(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"agenterdemand":[{"info_id":"001","store_id":"001","store_name":"世达旗舰店","brand_name":"世达","region_name":"江苏","release_time":"2017/01/01 09:00:00","num":10,"hasnum":2,"surplus":8},{"info_id":"002","store_id":"001","store_name":"世达旗舰店","brand_name":"世达","region_name":"江苏","release_time":"2017/01/01 09:00:00","num":10,"hasnum":2,"surplus":8}],"map":[{"info_id":"001","store_id":"001","store_name":"世达旗舰店","lon":"12345698.25","lat":"25698742.23","icon":"icon1.jpg"},{"info_id":"002","store_id":"001","store_name":"世达旗舰店","lon":"12345698.25","lat":"25698742.23","icon":"icon1.jpg"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_agentpush_list(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"agentpush":[{"info_id":"001","investment_funds":1000,"region":"江苏","release_time":"2017/01/01 09:00:00","requirement":"代理商A","store_id":"001","store_name":"世达旗舰店","contact":"张先生","phone":"18912345678","address":"北京市朝阳区","cat_type_id":"001","cat_type_name":"电动工具-电动扳手","brand_name":"世达"},{"info_id":"002","investment_funds":1000,"region":"江苏","release_time":"2017/01/01 09:00:00","requirement":"代理商A","store_id":"001","store_name":"世达旗舰店","contact":"张先生","phone":"18912345678","address":"北京市朝阳区","cat_type_id":"001","cat_type_name":"电动工具-电动扳手","brand_name":"世达"}],"map":[{"info_id":"001","store_id":"001","store_name":"世达旗舰店","lon":"12345698.25","lat":"25698742.23","icon":"icon1.jpg"},{"info_id":"002","store_id":"001","store_name":"世达旗舰店","lon":"12345698.25","lat":"25698742.23","icon":"icon1.jpg"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_agentpush_detail(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"cat_type": "一级","investment_funds": 1000,"region": "江苏","release_time": "2017/01/01 09:00:00","requirement": "代理商A","contact": "18912345678","brand_name": "世达","store_name": "世达"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_agentdemand_apply(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"apply_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		//可选品牌
		function get_brand_list(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"brand":[{"id":"001","name":"世达"},{"id":"002","name":"博士"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		//返回信息
		return {
			//获取数据
//			get_agent: function(callback) {
//				var data = new Object();
////				data.top = ['找代理商', '找经销商', '代理信息', '招商信息'];
//				data.top = ['我要入驻', '我要加盟'];
//
//				//函数回调
//				if(callback)
//					callback(data);
//			},
			//代理商需求一览
			agentdemand_list: function(nPage,key, brand_id, region_id,demand_kind, callback,calldone) {
				Http.post({
					method: 'member.agentdemand.getlist',
					key: key,
					brand_id: brand_id,
					region_id: region_id,
					demand_kind:demand_kind,
					pagelimit: 5,
					nPage: nPage
				}, function(result) {
					if(callback)
						callback(get_data_agentdemand_getlist(result).result);
				}, function(err) {

				}, function() {
					//完成之后
					if(calldone)
					calldone();
				});
			},
			//代理推送的详细
			agentpush_list: function(nPage,key,cat_type_id,region_id,push_kind,callback,calldone) {
				Http.post({
					method: 'member.agentpush.getlist',
					pagelimit: 5,
					nPage: nPage,
					key:key,
					cat_type_id:cat_type_id,
					region_id:region_id,
					push_kind:push_kind
				}, function(result) {
					if(callback)
						callback(get_data_agentpush_list(result).result);
				}, function(err) {

				}, function() {
					if(calldone)
					calldone();
				});
			},
			agentpush_detail: function(info_id, callback) {
				Http.post({
					method: 'member.agentpush.detail',
					info_id: info_id
				}, function(result) {
					if(callback)
						callback(get_data_agentpush_detail(result).result);
				}, function(e) {

				}, function() {

				})
			},
			agentdemand_apply: function(info_id, annual_sales, stimated_sales, dealar_num, brand, apply_desc, callback) {
				var updateParams = new Object();
				updateParams.info_id = info_id;
				updateParams.annual_sales = annual_sales;
				updateParams.dealer_num = dealar_num;
				updateParams.brand_name = brand;
				updateParams.apply_desc = apply_desc;
				updateParams.stimated_sales = stimated_sales;
				updateParams = JSON.stringify(updateParams)
				
				Http.post({
					method: 'member.agentdemand.apply',
					updateParams: updateParams
				}, function(result) {
					if(callback)
						callback(get_data_agentdemand_apply(result))
				}, function(e) {

				}, function() {

				})
			},
			//可选品牌
			brand_list: function(callback) {
				Http.post({
					method: 'goods.brand.getlist'
				},
				function(result) {
					//请求成功
					if(callback)
						callback(get_brand_list(result).result);
				},
				function(e) {
					//请求异常
				},
				function() {
					//请求完成，一般不做什么事情
				});
			},
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Agent", factory);
});